package com.magenta.maxoptra.gis.utils;

import com.magenta.maxoptra.gis.GeoRoute;
import com.magenta.maxoptra.gis.GeoStatusCode;
import com.magenta.maxoptra.gis.GeographicCoordinates;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kuznetsovd
 * Date: 05.12.12
 * Time: 14:30
 * To change this template use File | Settings | File Templates.
 */
public class GetRouteByListProfiler extends AbstractGisProfiler {

    private String coordsDefinition = "";

    public GetRouteByListProfiler(String provider, String accountGlobalId, boolean enableProfiling, List<GeographicCoordinates> coordinates) {
        super(provider, accountGlobalId, enableProfiling);
        for (GeographicCoordinates c : coordinates) {
            coordsDefinition = coordsDefinition + printPoint(c) + ":";
        }
    }

    public GetRouteByListProfiler(String provider, String accountGlobalId, boolean enableProfiling, GeographicCoordinates from, int listSize) {
        super(provider, accountGlobalId, enableProfiling);
        coordsDefinition = printPoint(from) + " -> " + listSize;
    }

    @Override
    public String getInitialInfo() {
        return provider + separator + accountGlobalId + separator + coordsDefinition;
    }

    public void logDuration(GeoRoute route) {
        if (route!=null) {
            if (route.getDistanceInKM() >=0) {
                logDuration(distanceFormat.format(route.getDistanceInKM())+" km"+separator + distanceFormat.format(route.getDurationInMinutes())+" min");
            } else {
                GeoStatusCode statusCode = GeoStatusCode.getStatusCode((int)Math.round(route.getDistanceInKM()));
                if (statusCode!=null) {
                    logError("error:"+statusCode.getDescription());
                } else {
                    logError("error:"+route.getDistanceInKM());
                }
            }
        }
    }

    public void logDuration(int size) {
        logDuration("result routeList.count:"+size);
    }


}
